package model.environment;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

public class StaticInfo {

	public static final int OUR_SHOP_ID = 128;
	public static final long UPDATE_TIMEOUT = 60 * 1000;
	public static final String SHOP_KEY = "75331DB0A25A35072535B90F";

	public static enum Message {
		LOGIN_OK, LOGIN_FAILED, 
		CREATEUSER_OK, 
		CREATEUSER_FAILED, 
		CHECKOUT_OK, 
		CHECKOUT_FAILED,
		CHECKOUT_MIXED, 
		EDIT_ITEM_OK, 
		EDIT_ITEM_FAILED, 
		CREATE_ITEM_FAILED, 
		ADJUST_STOCK_FAILED,
		ADJUST_STOCK_OK,
		VALIDATE_ITEM_DESCRIPTION_FAILED
	};
	/**
	 * Returns a POST request's parameters as a map.
	 * @param request The request.
	 * @return A map of the POST request's parameters.
	 */
	public static Map<String, String> getPostData(HttpServletRequest request)
	{
		Map<String, String> result = new HashMap<String, String>();
		
		if (request.getMethod().equals("POST")) {
			Enumeration<String> headers = request.getParameterNames();
			
			while (headers.hasMoreElements()) {
				String thisElem = headers.nextElement();
				result.put(thisElem, request.getParameter(thisElem));
			}
		}
		
		return result;
	}
	
	/**
	 * Returns a GET request's parameters as a map.
	 * @param request The request.
	 * @return A map of the GET request's parameters.
	 */
	public static Map<String, String> getGetData(HttpServletRequest request) {
		Map<String, String> result = new HashMap<String, String>();
		
		if (request.getMethod().equals("GET")) {
			Enumeration<String> headers = request.getParameterNames();
			
			while (headers.hasMoreElements()) {
				String thisElem = headers.nextElement();
				result.put(thisElem, request.getParameter(thisElem));
			}
		}
		
		return result;
	}
}
